package com.colorlight.cloud.complete.entity.enumerate;

import com.colorlight.cloud.common.exception.ParameterException;
import com.colorlight.cloud.common.model.ExceptionEnum;
import com.colorlight.cloud.gateway.api.message.constraint.basics.ienum.EnumTrans;
import com.colorlight.iot.proto.complete.entity.CompleteEntity;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author Demon
 * @date 29/5/2024  上午11:32
 */
public enum LocationType implements EnumTrans<CompleteEntity.LocationType, LocationType> {
	/**
	 * 默认未知
	 * GPS全球定位系统使用的坐标系统
	 * 火星坐标系
	 * 百度坐标系，在GCJ-02（火星坐标系）的基础上进行了加密偏移处理
	 */
	
	LOCATION_TYPE_DEFAULT(CompleteEntity.LocationType.Location_Type_Default),
	WGS(CompleteEntity.LocationType.WGS),
	GCJ(CompleteEntity.LocationType.GCJ),
	BD09(CompleteEntity.LocationType.BD09),
	;
	
	private final Integer id;
	private final String name;
	private final CompleteEntity.LocationType locationType;
	
	LocationType(CompleteEntity.LocationType locationType) {
		this.id = locationType.getNumber();
		this.name = locationType.name();
		this.locationType = locationType;
	}
	
	/**
	 * @param locationType
	 * @return 对应的类型
	 */
	public static LocationType getLocationTypeStruct(CompleteEntity.LocationType locationType) {
		Objects.requireNonNull(locationType, "locationType can not be null.");
		return Arrays.stream(LocationType.values())
				.filter(e -> e.name.equals(locationType.name()))
				.findFirst()
				.orElseThrow(() -> new ParameterException(ExceptionEnum.NOT_EXIST_ENUM));
	}
	
	@Override
	public CompleteEntity.LocationType toProto() {
		return this.locationType;
	}
	
	@Override
	public LocationType formProto(CompleteEntity.LocationType locationType) {
		return getLocationTypeStruct(locationType);
	}
}

	

